package com.example.a15787.weather_zyy_1235;
import org.json.JSONArray;
import org.json.JSONObject;

import java.util.List;

public class WeatherResponse {
    public int status;
    public String message;
    public List<City> cities;

    public static class City {
        public String cityId;
        public String cityName;
        public List<Forecast> weatherForecast;
        public  String background;
        public  String getCityId(){
            return cityId;
        }
        public void setCityId(String cityId){
            this.cityId=cityId;
        }
        public String getCityName() {
            return cityName;
        }

        public List<Forecast> getWeatherForecast() {
            return weatherForecast;
        }
    }

    public static class Forecast {
        public String date;
        public String weather;
        public Temperature temperature;
        public String wind;
        public String icon;
        public int humidity;
        public double pm25;
        public double getPm25(){
            return pm25;
        }
        public int getHumidity() {
            return humidity;
        }
        public String getDate() {
            return date;
        }

        public String getWeather() {
            return weather;
        }

        public Temperature getTemperature() {
            return temperature;
        }

        public String getWind() {
            return wind;
        }

        public String getIcon() {
            return icon;
        }
    }

    public static class Temperature {
        public int min;
        public int max;

        public int getMin() {
            return min;
        }

        public int getMax() {
            return max;
        }
    }

    @Override
    public String toString() {
        try {
            JSONObject json = new JSONObject();

            JSONArray citiesArray = new JSONArray();
            for (City city : cities) {
                JSONObject cityObj = new JSONObject();
                cityObj.put("cityId", city.cityId);
                cityObj.put("cityName", city.cityName);

                JSONArray forecastArray = new JSONArray();
                for (Forecast forecast : city.weatherForecast) {
                    JSONObject forecastObj = new JSONObject();
                    forecastObj.put("date", forecast.date);
                    forecastObj.put("weather", forecast.weather);

                    JSONObject tempObj = new JSONObject();
                    tempObj.put("min", forecast.temperature.min);
                    tempObj.put("max", forecast.temperature.max);
                    forecastObj.put("temperature", tempObj);

                    forecastObj.put("wind", forecast.wind);
                    forecastObj.put("icon", forecast.icon);
                    forecastObj.put("humidity", forecast.humidity);
                    forecastObj.put("pm25", forecast.pm25);

                    forecastArray.put(forecastObj);
                }

                cityObj.put("weatherForecast", forecastArray);
                citiesArray.put(cityObj);
            }

            json.put("cities", citiesArray);
            return json.toString();
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }
}